import getApiData, { getCPASTableAipsData, getNestApiData } from "@/services/cpasRequest";
import {
  queryVerifyState,
} from "@/services/annotaionAnalysis";
export const queryVerifyStatefs = async (params: any) => {
  const res = await queryVerifyState(params)
  return res
}

export async function getWscwbbData(params: {
  dbname: string;
  type: string;
  cols: string;
  keys: string;
  filterConditions: string
}) {
  try {
    const res = await getApiData("account.ws.wscwbb", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.ws.wscwbb出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.ws.wscwbb出错了！',
      success: false,
    });
  }

}

export async function getYearADate(params: {
  dbname: string;
}) {
  try {
    const res = await getApiData("cpasTable.getYearADate", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getDataList出错了！',
      success: false,
    });
  }
}

/**
 * 获取基础报表数据列映射
 */
export const getColumnsMapByReport = async (params: any) => {
  try {
    const res = await getCPASTableAipsData('getColumnsMapByReport', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getColumnsMapByReport出错了！',
      success: false,
    });
  }
};

/**
 * 获取报表基础数据行映射
 * @param tid
 */
export const getRowsMapByReport = async (params: any) => {

  try {
    const res = await getCPASTableAipsData('getRowsMapByReport', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口getRowsMapByReport出错了！',
      success: false,
    });
  }

};

/**
 * 获取表数据根据name
 */

export const getDesignTableInfoByNameApi = async (params: any) => {

  const res = await getCPASTableAipsData('getCpasTableDataByName', params)
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.reject({
    data: res.data,
    success: false,
  });
};



// 校验结果
export async function gettableIsVerifyTid(params: {
  tableName: string;
  dbname: string;
  isTid: boolean
}) {
  try {
    const res = await getApiData("account.design_table.isVerifyAndTid", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.design_table.isVerify出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.design_table.isVerify出错了！',
      success: false,
    });
  }
}



export async function getTableperiodAndPointList(params: {
  dbname: string;
  isDesc: boolean;
  reportType: number
}) {
  try {
    const res = await getApiData("account.timeList.periodAndPoint", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.timeList.periodAndPoint出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.timeList.periodAndPoint出错了！',
      success: false,
    });
  }
}

export async function getTableperiodAndPointList111(params: {
  dbname: string;
  isDesc: boolean;
}) {
  try {
    const res = await getApiData("account.timeList.periodAndPoint", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.timeList.periodAndPoint出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.timeList.periodAndPoint出错了！',
      success: false,
    });
  }
}


export async function getPeriodInfo(params: {
  dbname: string;
}) {
  try {
    const res = await getApiData("account.getPeriodInfo", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        success: true,
      });
    }
    return Promise.resolve({
      data: '接口account.getPeriodInfo出错了！',
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口account.getPeriodInfo出错了！',
      success: false,
    });
  }
}


// 批量计算模板
export async function reCalculateNotesInitApi(params: {
  dbname: string;
  data_id?: string;
  postCpasTableData: any[];
}) {
  try {
    const res = await getNestApiData('/cpasTableEngine/fsReCalculateNotes', 'post', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.ok,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.ok,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口/template/importTemplate,请求失败！',
      success: false,
    });
  }
}






// 初始化模板
export async function templateInitApi(params: {
  dbName: string;
  templateName: string;
  tableNames: string[];
  type: string;
  dataId?: string;
}) {
  try {
    const res = await getNestApiData('/template/importTemplate', 'post', params)
    if (res.ok) {
      return Promise.resolve({
        data: res.ok,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.ok,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: '接口/template/importTemplate,请求失败！',
      success: false,
    });
  }
}


// 初始化模板
export async function saveTemplateApi(params: {
  dbName: string;
  templateName: string;
  tableNames?: string[];
  type: string;
  dataId?: string;
}) {
  try {
    const res = await getNestApiData("/template/exportDataToSqlite", "post", params);
    if (res.ok) {
      return Promise.resolve({
        data: res.data,
        msg: res.msg,
        success: true,
      });
    }
    return Promise.resolve({
      data: res.data,
      msg: res.msg,
      success: false,
    });
  } catch (error) {
    return Promise.resolve({
      data: "接口/template/exportDataToSqlite,请求失败！",
      success: false,
    });
  }
}